package d5_stream;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class t6copy {
    @Test
    public void test() throws Exception {
        File srcpt = new File("D:\\wuyong\\AA1BAd5P.jfif");
        File destpt = new File("D:\\wuyong\\bbb");

        FileInputStream fis = new FileInputStream(srcpt);
        FileOutputStream fos = new FileOutputStream(destpt);

        FileChannel in = fis.getChannel();
        FileChannel out = fos.getChannel();

        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while(true){
            buffer.clear();

            int flag = in.read(buffer);
            if(flag == -1){
                break;
            }
            buffer.flip();
            out.write(buffer);
        }

        in.close();
        out.close();
        System.out.println("复制完成");
    }
}
